package com.banmao.mall.controller.admin;

import com.banmao.mall.mapper.CommentMapper;
import com.banmao.mall.model.bo.admin.comment.ReplyBO;
import com.banmao.mall.model.pojo.Comment;
import com.banmao.mall.model.vo.BaseRespVO;
//import com.banmao.mall.model.vo.admin.advertising.AdListVO;
import com.banmao.mall.model.vo.admin.comment.CommentListVO;
import com.banmao.mall.model.vo.admin.statistic.UserTotalRowsVO;
import com.banmao.mall.model.vo.admin.statistic.UserTotalVO;
import com.banmao.mall.service.admin.AdService;
import com.banmao.mall.service.admin.CommentService;
import com.banmao.mall.service.admin.StatisticService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/admin")
public class CommentController {

    @Autowired
    CommentService commentService;

    @Autowired
    CommentMapper commentMapper;

    @RequestMapping("/comment/list")
    public BaseRespVO commentList(Integer page, Integer limit, String sort, String order, Integer userId, Integer valueId) {
//        1.获取固定页码的评论
//        2.查询评论总数
//        3.封装CommentListVO对象
//        4.封装BaseRespVO对象
        List<Comment> commentList = commentService.getCommentListByMulCondition(page, limit, sort, order, userId, valueId);
        Integer integer = commentMapper.selectCommentsCount();

        CommentListVO commentListVO = new CommentListVO();
        commentListVO.setTotal(integer);
        commentListVO.setItems(commentList);
        return BaseRespVO.ok(commentListVO, "成功", 0);
    }

    @RequestMapping("/order/reply")
    @RequiresPermissions("admin:order:reply")
    public BaseRespVO commentReply(@RequestBody ReplyBO replyBO) {
//        1.先检查是否评论
//        2.如果没有，添加评论
        return BaseRespVO.ok(null, "订单商品已回复", 622);
    }

    @RequestMapping("/comment/delete")
    @RequiresPermissions("admin:comment:delete")
    public BaseRespVO deleteComment(@RequestBody Comment comment) {
        int i = commentMapper.deleteWithLogicByKey(comment.getId());
        return BaseRespVO.ok(null, "成功", 0);
    }

}
